package com.meetingshow.meeting.service.util;

import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.meetingshow.common.base.dao.model.QueryStruct;
import com.meetingshow.common.base.dao.model.Relation;
import com.meetingshow.common.base.dao.model.RelationList;
import com.meetingshow.common.base.service.BaseQueryParasBuilder;
import com.meetingshow.meeting.service.model.MeetingQueryParas;

public class MeetingQueryParasBuilder extends BaseQueryParasBuilder {
    public static QueryStruct meetingQueryBuilder(
            QueryStruct queryStruct, MeetingQueryParas meetingQueryParas)
            throws Exception {
        
        builderInit(meetingQueryParas, queryStruct);

        Map<String, Object> exactMap = queryStruct.getExactMap();
        Map<String, String> mistinessMap = queryStruct.getMistinessMap();
        RelationList relationList = queryStruct.getRelationList();
        RelationList dateList = queryStruct.getDateList();
        
        if (StringUtils.isNotBlank(meetingQueryParas.getMeetingId_e())) {
            exactMap.put(MeetingServiceParas.MEETING_ID, new Integer(meetingQueryParas.getMeetingId_e()));
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getCityId_e())) {
            exactMap.put(MeetingServiceParas.MEETING_CITY_ID, new Integer(meetingQueryParas.getCityId_e()));
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getIndustryId_e())) {
            exactMap.put(MeetingServiceParas.MEETING_INDUSTRY_ID, new Integer(meetingQueryParas.getIndustryId_e()));
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getName_e())) {
            exactMap.put(MeetingServiceParas.MEETING_NAME, meetingQueryParas.getName_e());
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getName())) {
            mistinessMap.put(MeetingServiceParas.MEETING_NAME, meetingQueryParas.getName());
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getRecommend_e())) {
            exactMap.put(MeetingServiceParas.MEETING_RECOMMEND, new Integer(meetingQueryParas.getRecommend_e()));
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getRecommend_e_ne())) {
            Relation relation = new Relation();
            relation.setObjName(MeetingServiceParas.MEETING_RECOMMEND);
            relation.setRelation("<>");
            relation.setValue(meetingQueryParas.getRecommend_e_ne());
            relationList.add(relation);
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getValuable_e())) {
            exactMap.put(MeetingServiceParas.MEETING_VALUABLE, new Integer(meetingQueryParas.getValuable_e()));
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getValuable_e_ne())) {
            Relation relation = new Relation();
            relation.setObjName(MeetingServiceParas.MEETING_VALUABLE);
            relation.setRelation("<>");
            relation.setValue(meetingQueryParas.getValuable_e_ne());
            relationList.add(relation);
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getHot_e())) {
            exactMap.put(MeetingServiceParas.MEETING_HOT, new Integer(meetingQueryParas.getHot_e()));
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getHot_e_ne())) {
            Relation relation = new Relation();
            relation.setObjName(MeetingServiceParas.MEETING_HOT);
            relation.setRelation("<>");
            relation.setValue(meetingQueryParas.getHot_e_ne());
            relationList.add(relation);
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getOrderByCreateTime())) {
            Relation queryOrder = new Relation();
            queryOrder.setObjName(MeetingServiceParas.MEETING_CREATETIME);
            queryOrder.setRelation(meetingQueryParas.getOrderByCreateTime());
            queryStruct.setQueryOrder(queryOrder);
        }
        
        if (StringUtils.isNotBlank(meetingQueryParas.getMeetingDate())) {
            Relation relation = new Relation();
            relation.setObjName(MeetingServiceParas.MEETING_STARTDATE);
            relation.setRelation("<=");
            relation.setValue(meetingQueryParas.getMeetingDate());
            
            dateList.add(relation);
            
            relation = new Relation();
            relation.setObjName(MeetingServiceParas.MEETING_ENDDATE);
            relation.setRelation(">=");
            relation.setValue(meetingQueryParas.getMeetingDate());
            
            dateList.add(relation);
        }
        
        pageBuilder(queryStruct, meetingQueryParas);
        
        return queryStruct;
    }
}
